new Vue({
    el: '#app',
    data: {
        msg: '233',
        menuList: [],
        globelTopAdd: false,
        gloabelTopDel: false,
    },
    mounted: function() {

        //异步取回
        this.menuList = [{
            menuName: '消息待办',
            url: '../error/404.html?id=2',
            iconBgCls: 'bg_5BD9C5',
            iconCls: 'fa-envelope-open',
            //iconImgUrl: '../static/images/deskCloud/注销申请.png',
            isTop: false,
            groupId: 1,
            groupName: '常用功能',
            toDel: false,
            toAdd: false
        }, {
            menuName: '工作提醒',
            url: '../error/404.html?id=3',
            iconBgCls: 'bg_5ED5F3',
            iconCls: 'fa-bell',
            //iconImgUrl: '../static/images/deskCloud/失效声明.png',
            isTop: false,
            groupId: 1,
            groupName: '常用功能',
            toDel: false,
            toAdd: false
        }, {
            menuName: '监管信息',
            url: '../error/404.html?id=5',
            iconBgCls: 'bg_5ED5F3',
            iconCls: 'fa-map',
            iconImgUrl: '',
            isTop: false,
            groupId: 1,
            groupName: '常用功能',
            toDel: false,
            toAdd: false
        }, {
            menuName: '问责建议',
            url: '../error/404.html?id=6',
            iconBgCls: 'bg_5ED5F3',
            iconCls: 'fa-graduation-cap',
            iconImgUrl: '',
            isTop: false,
            groupId: 1,
            groupName: '常用功能',
            toDel: false,
            toAdd: false
        }, {
            menuName: '数据中心',
            url: '../error/404.html?id=7',
            iconBgCls: 'bg_5ED5F3',
            iconCls: 'fa-bar-chart',
            iconImgUrl: '',
            isTop: false,
            groupId: 1,
            groupName: '常用功能',
            toDel: false,
            toAdd: false
        }, {
            menuName: '报表中心',
            url: '../error/404.html=8',
            iconBgCls: 'bg_5ED5F3',
            iconCls: 'fa-twitter',
            iconImgUrl: '',
            isTop: false,
            groupId: 1,
            groupName: '常用功能',
            toDel: false,
            toAdd: false
        }, {
            menuName: '污染源统一编码=10',
            url: '../error/404.html',
            iconBgCls: 'bg_5ED5F3',
            iconCls: 'fa-random',
            iconImgUrl: '',
            isTop: false,
            groupId: 1,
            groupName: '日常执法监督情况',
            toDel: false,
            toAdd: false
        }, {
            menuName: '污染源统一编码=10',
            url: '../error/404.html',
            iconBgCls: 'bg_5ED5F3',
            iconCls: 'fa-random',
            iconImgUrl: '',
            isTop: false,
            groupId: 1,
            groupName: '环保督察检查情况',
            toDel: false,
            toAdd: false
        }, {
            menuName: '排污许可证',
            url: '../error/404.html',
            iconBgCls: 'bg_5ED5F3',
            iconCls: 'fa-random',
            iconImgUrl: '',
            isTop: false,
            groupId: 1,
            groupName: '问责建议清单管理',
            toDel: false,
            toAdd: false
        }];

    },
    methods: {
        changePageUrl: function(item) {

            var a = window.parent.app.changePageUrl({
                url: item.url,
                menuName: item.menuName,
                menuPath: [item.groupName]
            });

        },
        topList: function() {
            return _.filter(this.menuList, function(item) { return item.isTop == true; });
        },
        unTopList: function() {
            return _.filter(this.menuList, function(item) { return item.isTop == false; });
        },
        getGroupList: function() {
            return _.groupBy(this.menuList, function(item) { return item.groupName; });
        },
        getUnTopGroupList: function() {
            return _.groupBy(this.unTopList(), function(item) { return item.groupName; });
        },
        toTopDelState: function() {
            this.gloabelTopDel = true;
            _.each(this.menuList, function(item) {
                if (item.isTop == true) {
                    item.toDel = true;
                }
            });
        },
        outTopDelState: function() {
            this.gloabelTopDel = false;
            _.each(this.menuList, function(item) {
                if (item.isTop == true) {
                    item.toDel = false;
                }
            });
        },
        topListRemove: function(item, index) {
            item.isTop = false;
            item.toDel = false;
        },
        toAddState: function() {
            this.globelTopAdd = true;
            _.each(this.menuList, function(item) {
                if (item.isTop == false) { //非顶的
                    item.toAdd = true;
                }
            });
        },
        outAddState: function() {
            this.globelTopAdd = false;
            _.each(this.menuList, function(item) {
                if (item.isTop == false) { //非顶的
                    item.toAdd = false;
                }
            });
        },
        topListAdd: function(item, index) {
            item.isTop = true;
            item.toAdd = false;
        }
    },
    watch: {
        menuList: {
            handler: function(curVal, oldVal) {

                setTimeout(function() {
                    jQuery(".slideMenu").slide({
                        effect: "left"
                    });
                }, 0);

                var curTop = _.filter(this.menuList, function(item) { return item.isTop == true; });
                if (curTop.length == 0) {
                    this.gloabelTopDel = false;
                }


                if (this.getUnTopGroupList().length == 0) {
                    this.globelTopAdd = false;
                }

            },
            deep: true
        }

    }
});